<template>
  <view class="submitBar">
    <view class="client">
      <u-icon class="icon" name="server-fill"></u-icon>
      联系客服
    </view>
    <navigator open-type="switchTab" url="/pages/cart/cart" class="cart">
      <u-icon class="icon" name="shopping-cart"></u-icon>
      购物车
      <view v-if="totalProdType > 0" class="number">{{totalProdType}}</view>
    </navigator>
    <view class="addCart" @click="addCart">
      加入购物车
    </view>
    <view class="buyNow">
      立即购买
    </view>
  </view>
</template>

<script>
// import { mapGetters } from 'vuex'
export default {
  props: {
    detail: {
      type: Object,
      required: true
    }
  },
  computed: {
    // ...mapGetters(['totalProdType'])
    // 辅助函数实际的作用是生成以下函数
    totalProdType() {
      return this.$store.getters.totalProdType
    }
  },
  methods: {
    addCart() {
      const product = {
        goods_id: this.detail.goods_id,
        goods_price: this.detail.goods_price,
        goods_name: this.detail.goods_name,
        goods_pic: this.detail.pics[0].pics_sma_url,
        number: 1,
        isChecked: true
      }
      this.$store.commit('cart/addCart', product)
      console.log(this.$store.state.cart.list);
    }
  }
}
</script>

<style lang="scss" scoped>
.submitBar {
  position: fixed;
  bottom: 0;
  left: 0;
  background: #fff;
  width: 100%;
  border: 4rpx solid #ddd;
  display: flex;
  height: 94rpx;
  justify-content: space-around;
  align-items: center;
  .client, .cart {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 24rpx;
    .icon {
      font-size: 40rpx;
    }
  }
  .cart {
    position: relative;
    .number {
      position: absolute;
      top: -10rpx;
      right: -16rpx;
      color: #fff;
      background: $theme-color;
      padding: 12rpx;
      line-height: 16rpx;
      border-radius: 8rpx;
      font-size: 22rpx;
    }
  }
  .addCart {
    font-size: 30rpx;
    background: #FCAA23;
    color: #fff;
    line-height: 60rpx;
    padding: 0 33rpx;
    border-radius: 30rpx;
  }
  .buyNow {
    font-size: 30rpx;
    background: $theme-color;
    color: #fff;
    line-height: 60rpx;
    padding: 0 33rpx;
    border-radius: 30rpx;
  }
}
</style>